<template>
  <!-- 库位搜索 -->
  <base-table-select
    v-model="warehouse"
    :disabled="disabled"
    placeholder="请输入库位选择搜索"
    class="my-form_input"
    :api-obj="warehouseObj"
    :params="params"
    :table-width="300"
    :props="warehouseProps"
    @change="change"
  >
    <el-table-column prop="code" min-width="100" label="库位码" align="center" />
  </base-table-select>
</template>

<script>
export default {
  name: 'WarehouseSelect',
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    param: {
      type: Object,
      default: () => {
        return {}
      }
    },
    data: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      warehouse: {},
      warehouseObj: this.reqCondition, // 库位列表请求接口
      warehouseProps: {
        label: 'code',
        value: 'code',
        keyword: 'regionCode',
        page: 'current',
        pageSize: 'size'
      },
      params: {}
    }
  },
  watch: {
    param: {
      handler() {
        Object.assign(this.params, this.param)
      },
      deep: true,
      immediate: true
    },
    data: {
      handler(val) {
        this.warehouse = Object.assign({}, this.warehouse, val)
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    async reqCondition(params) {
      return new Promise(resolve => {
        if (this.params.startDate) {
          this.$http.put('/ly-wms-servicer/storage/region/getStorageRegionByCondition', params, res => {
            if (res && res.code != 0) {
              this.$message.error(res.message || '查询错误')
            }
            res.responseBody.records = Array.isArray(res.responseBody.records) ? res.responseBody.records : []
            res.responseBody.total = res.responseBody.total ? res.responseBody.total - 0 : 0
            resolve(res)
          })
        } else {
          this.$message.warning('请先选择商品的生产日期')
        }
      })
    },
    change() {
      this.$emit('change', this.warehouse)
    },
    clear() {
      this.warehouse = {}
    }
  }
}
</script>

<style lang="scss" scoped></style>
